#
# @lc app=leetcode.cn id=1143 lang=python3
#
# [1143] 最长公共子序列
#

# @lc code=start
class Solution:
    @lru_cache()
    def longestCommonSubsequence(self, text1: str, text2: str) -> int:
        if len(text1) == 0 or len(text2) == 0:
            return 0
        if text1[-1] == text2[-1]:
            return 1 + self.longestCommonSubsequence(text1[0:-1], text2[0: -1])
        else:
            return max(self.longestCommonSubsequence(text1, text2[0:-1]),  self.longestCommonSubsequence(text1[0:-1], text2))
        
# @lc code=end

